<?php
/**
 * Bdc Application level Controller
 *
 */
class WorkShopAppController extends AppController
{
    # User Types
    var $reminder_times = array(
        '-1 day'=>'1 Day Before',
        '-2 day'=>'2 Days Before',
        '-3 day'=>'3 Days Before',
        '-4 day'=>'4 Days Before',
        '-5 day'=>'5 Days Before',
        '-6 day'=>'6 Days Before',
        '-1 week'=>'1 week Before',
        '-2 week'=>'2 weeks Before',
        '-3 week'=>'3 weeks Before',
        '-1 month'=>'1 Month Before'
    );

    function beforeFilter($param_array = null)
    {
        parent::beforeFilter();

        $user_type = $this->Auth->user('user_type');
        $user_level = $this->Auth->user('user_level');
        if ($user_type != 'service_adviser') {
            $this->redirect(array('controller' => 'Dashboard', 'action' => 'index'));
        }

        if(in_array('Allow All',$param_array['user_levels'])){

        }
        else{
            if(in_array($user_level,$param_array['user_levels'])){

            }
            else{
                $this->redirect(array('controller' => 'Dashboard', 'action' => 'index'));
            }
        }
    }


    function sendMessage($params){
        $all_users = $this->getMessageAddressList($params['bdc'],$params['omc'],$params['bdc_user_types'],$params['omc_user_types'],$params['excluded_users'],$params['message_origin']);
        $message['Message']=array(
            'title'=>$params['title'],
            'content'=>$params['content'],
            'user_id'=>$params['sender'],
            'msg_type'=>$params['msg_type']
        );
        return $this->send_message($message,$all_users);
    }


    function getCustomersList(){
        $type = 'service_customer';
        $fields = array('Customer.id', 'Customer.name');
        $contain=array();
        $recursive = -1;
        $c = $this->Customer->getCustomers($type,$fields,$contain,$recursive);
        $c_lists = array();
        foreach ($c as $value) {
            $c_lists[] = array(
                'id'=>$value['Customer']['id'],
                'name'=>$value['Customer']['name'],
            );
        }
        return $c_lists;
    }

}
